#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

struct Triple {
    int row;
    int col;
    int value;
};

void transpose(const std::vector<Triple>& matrix, int rows, int cols, int numNonZero, std::vector<Triple>& transposedMatrix) {
    std::vector<int> rowSize(cols, 0);
    std::vector<int> startPos(cols + 1, 0);

    // 计算每一列有多少个非零元
    for (int i = 0; i < numNonZero; i++) {
        rowSize[matrix[i].col - 1]++;
    }

    // 计算每一列的起始位置
    startPos[0] = 0;
    for (int i = 1; i <= cols; i++) {
        startPos[i] = startPos[i - 1] + rowSize[i - 1];
    }

    // 构造转置矩阵
    for (int i = 0; i < numNonZero; i++) {
        int pos = startPos[matrix[i].col - 1]++;
        transposedMatrix[pos].row = matrix[i].col;
        transposedMatrix[pos].col = matrix[i].row;
        transposedMatrix[pos].value = matrix[i].value;
    }
}

int main() {
    int rows, cols, numNonZero;
    std::cin >> rows >> cols >> numNonZero;

    std::vector<Triple> matrix(numNonZero);
    for (int i = 0; i < numNonZero; i++) {
        std::cin >> matrix[i].row >> matrix[i].col >> matrix[i].value;
    }

    std::vector<Triple> transposedMatrix(numNonZero);

    transpose(matrix, rows, cols, numNonZero, transposedMatrix);

    // 打印转置后的矩阵
    // for (int i = 0; i < numNonZero; i++) {
    //     std::cout << "(" << transposedMatrix[i].row << ", " << transposedMatrix[i].col << ", " << transposedMatrix[i].value << ")\n";
    // }

    // 输出转置后的矩阵
    std::vector<std::vector<int>> result(cols, std::vector<int>(rows, 0));

    for (int i = 0; i < numNonZero; i++) {
        result[transposedMatrix[i].row - 1][transposedMatrix[i].col - 1] = transposedMatrix[i].value;
    }

    for (int i = 0; i < cols; i++) {  // 遍历所有行
        for (int j = 0; j < rows; j++) {
            if (j == rows - 1) {  // 如果是当前行的最后一个元素
                std::cout << result[i][j];  // 不加空格
            } else {
                std::cout << result[i][j] << " ";  // 其他元素后面加空格
            }
        }
        if (i < cols - 1) {  // 如果不是最后一行，则换行
            std::cout << "\n";
        }
    }    

    return 0;
}